//index.js
//获取应用实例
const app = getApp();
const name = [];
const num = [];
const monthcost = [];
const costrate = [];
const streetList = [];
const arr = [];
const arr1 = [];
const json = []
import wxCharts from '../../utils/wxcharts.js'

Page({
  data: {
    height: 'calc(100% - 80rpx)',
    currentTab: 0,
  },
  /** 
    * 滑动切换tab 
    */
  bindChange: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current });
  },

  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {

      return false;

    } else {

      that.setData({

        currentTab: e.target.dataset.current

      })

    }

  },

  getNolead: function (res) {
    name.splice(0, name.length)
    num.splice(0, num.length)
    for (var i = 0; i < res.length; i++) {
      name.push(res[i].name);
      num.push(res[i].num);
    }
    new wxCharts({
      canvasId: 'columnCanvas2',
      type: 'column',
      animation: true,
      categories: name,
      series: [{
        data: num,
        color: '#FF2A0B'
      }],
      yAxis: {
        min: 0
      },
      xAxis: {
        disableGrid: false,
        type: 'calibration'
      },
      extra: {
        column: {
          width: 15
        }
      },
      width: 300,
      height: 200,
      dataLabel: true,
      legend: false
    });
  },
  getcomplete: function (res) {
    monthcost.splice(0, monthcost.length)
    costrate.splice(0, costrate.length)
    streetList.splice(0, streetList.length)
    for (var i = 0; i < res.length; i++) {
      monthcost.push(res[i].monthcost);
      costrate.push(res[i].costrate);
      streetList.push(res[i].street);
    }
    new wxCharts({
      canvasId: 'columnCanvas',
      type: 'column',
      animation: true,
      categories: streetList,
      series: [{
        data: costrate,
        color: '#FF2A0B'
      }],
      yAxis: {
        min: 0
      },
      xAxis: {
        disableGrid: false,
        type: 'calibration'
      },
      extra: {
        column: {
          width: 20
        }
      },
      width: 300,
      height: 200,
      dataLabel: true,
      legend: false
    });
    new wxCharts({
      canvasId: 'columnCanvas1',
      type: 'column',
      animation: true,
      categories: streetList,
      series: [{
        data: monthcost,
        color: '#FF2A0B'
      }],
      yAxis: {
        min: 0
      },
      xAxis: {
        disableGrid: false,
        type: 'calibration'
      },
      extra: {
        column: {
          width: 20
        }
      },
      width: 300,
      height: 200,
      dataLabel: true,
      legend: false
    });
    console.log(monthcost)
  },
  getyearMoney: function (res) {
    arr.splice(0, arr.length)
    arr1.splice(0, arr1.length)
    json.splice(0, json.length)
    var color = ["#a6fe54", "#1E385D", "#DFFE1A", "#24DBFA", "#50ACEF", "#02B3D5", "#000ADE", "#C9FCC1", "#4FA8FA", "#FC6763"]
    var list = res[0]
    for (let i in list) {
      arr.push(list[i])
    }
    for (let key in list) {
      arr1.push(key)
    }
    for (var i = 0; i < arr.length; i++) {
      var j = {}
      j.name = arr1[i]
      j.data = arr[i]
      j.color = color[i]
      // 这里还可以继续添加属性 j.属性 = 值
      json.push(j)
    }
    console.log(json)
    new wxCharts({
      animation: true,
      canvasId: 'pieCanvas',
      type: 'pie',
      series: json,
      width: 300,
      height: 300,
      dataLabel: true
      // legend:true
    })
  },
  onLoad: function () {
    app.thirdScript.http.post('project/getNolead', { street: wx.getStorageSync('userInfo').officeName }, 'getNolead', this)
    app.thirdScript.http.post('project/getyearMoney', { street: wx.getStorageSync('userInfo').officeName }, 'getyearMoney', this)
    app.thirdScript.http.post('project/getcomplete', { street: wx.getStorageSync('userInfo').officeName }, 'getcomplete', this)
  }
})
